package logic

import (
	"context"
	"srv/model/mysql"

	"srv/internal/svc"
	"srv/srv"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodListLogic {
	return &GoodListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodListLogic) GoodList(in *srv.GoodListRequest) (*srv.GoodListResponse, error) {
	// todo: add your logic here and delete this line

	var good []mysql.Good
	mysql.DB.Where("good_state = ?", in.GoodState).Find(&good)
	var lists []*srv.GoodList
	for _, m := range good {
		list := srv.GoodList{
			GoodName:  m.GoodName,
			GoodPrice: float32(m.GoodPrice),
			GoodStock: int64(m.GoodStock),
			GoodSell:  int64(m.GoodSell),
			GoodState: int64(m.GoodState),
		}
		lists = append(lists, &list)
	}

	return &srv.GoodListResponse{List: lists}, nil
}
